package me.luger.project.base.modules.sys.service;

import me.luger.core.aspect.cache.DataCache;
import me.luger.core.aspect.log.OpLog;
import me.luger.core.commom.util.DateUtil;
import me.luger.core.dao.nutz.entity.easyui.datagrid.DataGridRequest;
import me.luger.core.dao.nutz.entity.easyui.datagrid.DataGridResult;
import me.luger.core.dao.nutz.service.CurdService;
import me.luger.core.dao.nutz.entity.page.Pagination;
import me.luger.core.dao.nutz.entity.page.DataTableRequest;
import me.luger.core.dao.nutz.entity.page.DataTableResult;
import me.luger.project.base.modules.sys.dao.AdminUserDao;
import me.luger.project.base.modules.sys.entity.AdminUser;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class AdminUserService extends CurdService<AdminUser,Integer> {
    @Autowired
    private AdminUserDao adminUserDao;


    @Override
    public AdminUser insert(AdminUser adminUser) {
        return adminUserDao.insert(adminUser);
    }

    @Override
    public int delete(Integer... ids) {
        return adminUserDao.delete(ids);
    }

    @Override
    public int update(AdminUser AdminUser) {
        return adminUserDao.update(AdminUser);
    }

    @Override
    public int updateIgnoreNull(AdminUser AdminUser) {
        return adminUserDao.updateIgnoreNull(AdminUser);
    }


    @Override
    public AdminUser getById(Integer aLong) {
        return adminUserDao.getById(aLong);
    }

    @Override
    public List<AdminUser> listAll() {
        return adminUserDao.listAll();
    }

    @Override
    public Pagination<AdminUser> listPage(int pageNumber, int pageSize){
        return adminUserDao.listPage(pageNumber,pageSize);
    }

    @Override
    public DataTableResult<AdminUser> data(DataTableRequest dataTableRequest) {
        return adminUserDao.data(dataTableRequest);
    }

    @Override
    public DataGridResult<AdminUser> data(DataGridRequest dataGridRequest) {
        return adminUserDao.data(dataGridRequest);
    }

    @Cacheable(value = "instant_time_cache")
    @DataCache(cacheManager = "ehcache")
    public String getTime(){
        return DateUtil.nowWithFormat();
    }

    @DataCache(cacheManager = "redis",timeToLiveSeconds = 100,condition = "#test > 3")
    public AdminUser getAdminuser(int test){
        AdminUser adminUser = this.getById(1);
        adminUser.setPassword(DateUtil.nowWithFormat());
        return adminUser;
    }

    @OpLog(name = "更新管理员",detail = "更新前#{#adminUser.userName},#{#adminUser.id}",after = "更新后#{#result.userName}")
    public AdminUser updateTestOpLog(AdminUser adminUser) {
        adminUser.setUserName("ceshi中文1333");
        adminUserDao.updateIgnoreNull(adminUser);
        return adminUser;
    }
}
